import { getProductSearch } from '@/api/api'

const searchStore = {
  state: {
    searchList: {}
  },
  mutations: {
    SETPRODUCTSEARCH(state, searchList) {
      state.searchList = searchList
    }
  },
  actions: {
    //params形参：是当用户派发action时，第二个参数传递的，至少是一个空对象
    async setProductSearch({ commit }, searchParams = {}) {
      let result = await getProductSearch(searchParams);
      if (result.code == 200) {
      commit('SETPRODUCTSEARCH', result.data)
      // console.log(result.data)
      }
    }
  },

  //getters主要作用：简化仓库中的数组数据，使之更容易被使用(但不严谨)
  getters: {
    goodsList(state) {
      return state.searchList.goodsList ;
    },
    trademarkList(state) {
      return state.searchList.trademarkList ;
    },
    attrsList(state) {
      return state.searchList.attrsList ;
    },
    total(state) {
      return state.searchList.total ;
    }
  }
}

export default searchStore